package gov.kqqzyyy.monkey.orderpad.mytools;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * Created by Monkey on 2017/9/18.
 * 年龄生日等计算工具
 */

public class AgeUtil {

    //计算年龄
    public static int getAge(String birthday) {
        try {
            Date birth_date = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).parse(birthday);
            Calendar now_calendar = Calendar.getInstance();
            Calendar birth_calendar = Calendar.getInstance();
            birth_calendar.setTime(birth_date);
            return now_calendar.get(Calendar.YEAR) - birth_calendar.get(Calendar.YEAR);
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }
}
